package com.chinasofti.zbestadmin.web;


import com.chinasofti.zbestadmin.dao.model.Admin;
import com.chinasofti.zbestadmin.service.IAdminService;
import com.chinasofti.zbestadmin.web.form.AdminForm;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * <p>
 * 管理员表 前端控制器
 * </p>
 *
 * @author zbestadmin
 * @since 2019-05-29
 */
@Controller
@Slf4j
public class AdminController extends BaseController {

    @Autowired
    private IAdminService adminService;

    //去登录页面
    @RequestMapping("/admin")
    public String toLogin(){
        return "login1";
    }

    //登录操作
    @RequestMapping("/login")
    public String login(ModelMap modelMap , AdminForm adminForm){
        String loginAddress="404";
        Admin admin = adminService.findByAdminNameAndPassword(adminForm);
        modelMap.addAttribute("admin",admin);
        if(admin!=null){
            log.info(admin.toString());
            return "frame";
        }else {
            modelMap.addAttribute("msg","用户名或密码错误");
            return "login1";
        }
    }

}

